package com.hdu.clj.fitness

import android.content.Context
import android.database.sqlite.SQLiteDatabase

class UserdatabaseUtil {

    fun getBase(context: Context,curUserName:String):SQLiteDatabase{
        val dbHelper = userDatabase(context,"Users.db",1)
        val db = dbHelper.writableDatabase
        return db
    }

    private fun getUserBase(context: Context,curUserName:String):List<Int>{
        var dayNum = 0
        var totalNum = 0
        var cur_data = 0
        //用户总数据表
        val dbHelper = userDatabase(context,"Users.db",1)
        val db = dbHelper.writableDatabase

        var curUserData = db.rawQuery("select * from Users where name = ?", arrayOf(curUserName))
        if (curUserData.moveToFirst()){
            dayNum = curUserData.getInt(curUserData.getColumnIndex("dayNum"))
            totalNum = curUserData.getInt(curUserData.getColumnIndex("totalNum"))
            cur_data = curUserData.getInt(curUserData.getColumnIndex("total"))
        }
        return listOf(dayNum,totalNum,cur_data)
    }

    fun updateUserBase(context: Context,curUserName:String,cur_data:Int){
        //用户总数据表
        val dbHelper = userDatabase(context,"Users.db",1)
        val db = dbHelper.writableDatabase
        db.execSQL("update Users set total = ? where name = ?", arrayOf(cur_data,curUserName))

    }

    fun insertUserBase(){

    }

    fun deleteUserBase(){

    }
}